<?php
include("config.php");
if (!(isset($_SESSION["user"]) && $_SESSION["user"] != "") 
&& !(isset($_SESSION["auser"]) && $_SESSION["auser"] != "")) header('Location: index.php');
if (isset($adm_menu) && (!isset($_SESSION["auser"]) || $_SESSION["auser"] == "")) header('Location: index.php');

include("header.php");
include("menu.php");

	if (!isset($adm_menu)) {
		$script = "accounts.php";
	} else {
		$script = "aaccounts.php";
	}

$db_www = new DB($server_username,$server_pass,$server_db,$server,$driver);
if ($db_www->isConnected()) {	
	if (isset($adm_menu)) {
		$i_query = str_replace("<kodas>", $_SESSION['auser'], $i_query);
	} else {
		$i_query = str_replace("<kodas>", $_SESSION['user'], $i_query);
	}
	$minfo = $db_www->returnInfo($i_query);	

	
} else {
	die("Klientų aptarnavimo sistema laikinai neveikia.");
}

if (isset($_REQUEST["act"]) && isset($_REQUEST["nr"])){
	if ($_REQUEST["act"] == "confirm" || $_REQUEST["act"] == "unconfirm") {
		$test_query = str_replace("<im_kodas>", $minfo["N08_kodas_ks"], $accounts_query);
		$test_query .= " and i31_kodas_kr = '" . addslashes_mssql($_REQUEST["nr"]) . "'";
		$test_query = str_replace("<suma>", "I32_DEB_SUMA ", $test_query);
		$test = $db_www->returnList($test_query);
		if (empty($test)) {
			die("Patvirtinti/nepatvirtinti galima tik savo imones saskaitas");
		}
	} else {
		$test_query = str_replace("<im_kodas>", $minfo["N08_kodas_ks"], $accounts_query2);
		$test_query .= " and I06_KODAS_PO = '" . addslashes_mssql($_REQUEST["nr"]) . "'";
		$test = $db_www->returnList($test_query);
		if (empty($test)) {
			die("Patvirtinti/nepatvirtinti galima tik savo imones saskaitas");
		}	
	}
	if ($_REQUEST["act"] == "confirm") {
		$conf_query = str_replace("<kodas>", addslashes_mssql($_REQUEST["nr"]), $conf_query);
		$conf_query = str_replace("<status>", "+", $conf_query);
		$db_www->execute($conf_query);		
		logAction("Klientas patvirtino sąskaitą:" . $_REQUEST["docnr"],1);
	} else if ($_REQUEST["act"] == "unconfirm") {
		$conf_query = str_replace("<kodas>", addslashes_mssql($_REQUEST["nr"]), $conf_query);
		$conf_query = str_replace("<status>", "-", $conf_query);
		$db_www->execute($conf_query);
		logAction("Klientas nepatvirtino sąskaitos:" . $_REQUEST["docnr"],1);	
		addDocComment($_REQUEST["docnr"],$_REQUEST["comment"]);		
	} else if ($_REQUEST["act"] == "confirm2") {
		$conf_query2 = str_replace("<kodas>", addslashes_mssql($_REQUEST["nr"]), $conf_query2);
		$conf_query2 = str_replace("<status>", "+", $conf_query2);
		$db_www->execute($conf_query2);	
		logAction("Klientas patvirtino sąskaitą:" . $_REQUEST["docnr"],1);		
	} else if ($_REQUEST["act"] == "unconfirm2") {
		$conf_query2 = str_replace("<kodas>", addslashes_mssql($_REQUEST["nr"]), $conf_query2);
		$conf_query2 = str_replace("<status>", "-", $conf_query2);
		$db_www->execute($conf_query2);		
		logAction("Klientas nepatvirtino saskaitos:" . $_REQUEST["docnr"],1);
		addDocComment($_REQUEST["docnr"],$_REQUEST["comment"]);	
	}
}	else if (isset($_REQUEST["act"]) && isset($_REQUEST["dok_nr"]) && isset($_REQUEST["comment"])){
		addDocComment($_REQUEST["dok_nr"],$_REQUEST["comment"]);
}
$db_rdata = new DB($rdata_server_username,$rdata_server_pass,$rdata_server_db,$rdata_server,$rdata_driver);

include("accounts_filter.php");

?>
<!-- IE specific code: -->
<!--[if lte IE 9]> 
<style type="text/css"> 
#aep_ovrl { 
position: absolute; 
filter:alpha(opacity=70); 
top: expression(eval(document.body.scrollTop)); 
width: expression(eval(document.body.clientWidth)); 
} 
#aep_ww {  
position: absolute;  
top: expression(eval(document.body.scrollTop));  
} 
</style> 
<![endif]-->
<!-- ae_prompt HTML code -->
<div id="aep_ovrl" style="display: none;"></div>
<div id="aep_ww" style="display: none;">
<div id="aep_win"><div id="aep_t"></div>
<div id="aep_w"><span id="aep_prompt"></span>
<br />Komentaras: <input type="text" id="aep_text" onKeyPress=
"if((event.keyCode==10)||(event.keyCode==13)) ae_clk(1); if (event.keyCode==27) ae_clk(0);">
<br><div><input class="but bgfilter" type="button" id="aep_ok" onclick="ae_clk(1);" value="Gerai">
<input class="but bgfilter" type="button" id="aep_cancel" onclick="ae_clk(0);" value="Atšaukti">
</div></div>
</div>
</div>
<!-- ae_prompt HTML code -->
<SCRIPT language="JavaScript">
<!--
var dok_nr = null;
var kodas = null;
function comment(nr,val) {
	dok_nr = nr;
	ae_prompt( hw2, 'Įveskite komentarą sąskaitai: ' + nr, val);
}

function commentUnconfirm(knr,dnr,val) {
	dok_nr = dnr;
	kodas = knr;
	ae_prompt( hw3, 'Įveskite komentarą, kodėl netvirtinate: ' + dnr, val);
}

function commentUnconfirm2(knr,dnr,val) {
	dok_nr = dnr;
	kodas = knr;
	ae_prompt( hw4, 'Įveskite komentarą, kodėl netvirtinate: ' + dnr, val);
}

function hw4(n)
{
    if (n != null)
		window.location='<?php echo $script;?>?poz=<?php echo $poz;?>&act=unconfirm2&nr='+kodas+'&docnr='+dok_nr+'&comment='+n;
}

function hw3(n)
{
    if (n != null)
		window.location='<?php echo $script;?>?poz=<?php echo $poz;?>&act=unconfirm&nr='+kodas+'&docnr='+dok_nr+'&comment='+n;
}
 
function hw2(n)
{
    if (n != null)
		window.location='<?php echo $script;?>?poz=<?php echo $poz;?>&act=change&dok_nr='+dok_nr +'&comment='+n;
}

// This is variable for storing callback function 
var ae_cb = null;

 
// this is a simple function-shortcut 
// to avoid using lengthy document.getElementById 
function ae$(a) { return document.getElementById(a); } 
 
// This is a main ae_prompt function 
// it saves function callback  
// and sets up dialog 
function ae_prompt(cb, q, b) { 
	ae_cb = cb;
	ae$('aep_t').innerHTML = document.domain + ' klausimas:';
	ae$('aep_prompt').innerHTML = q;
	ae$('aep_text').value = b;
	ae$('aep_ovrl').style.display = ae$('aep_ww').style.display = '';
	ae$('aep_text').focus();
	ae$('aep_text').select();
} 
 
// This function is called when user presses OK(m=0) or Cancel(m=1) button 
// in the dialog. You should not call this function directly. 
function ae_clk(m) { 
	if (!m)  
		ae_cb(null);  // user pressed cancel, call callback with null 
	else {	    
		ae_cb(ae$('aep_text').value); // user pressed OK  
	}	
	// hide dialog layers  
	ae$('aep_ovrl').style.display = ae$('aep_ww').style.display = 'none';
}






function stat(n,nr,docnr)
{
    if (n == "+") {
		var answer = confirm("Ar tikrai patvirtinti?")
		if (answer){
			window.location='<?php echo $script;?>?poz=<?php echo $poz;?>&act=confirm&nr='+nr+'&docnr='+docnr ;
		}
	} else {
		var answer = confirm("Ar tikrai norite Nepatvirtinti?")
		if (answer){
			commentUnconfirm(nr,docnr,'');			
		}
	}	
}

function status2(n,nr,docnr)
{
    if (n == "+") {
		var answer = confirm("Ar tikrai patvirtinti?")
		if (answer){
			window.location='<?php echo $script;?>?poz=<?php echo $poz;?>&act=confirm2&nr='+nr+'&docnr='+docnr ;
		}
	} else {
		var answer = confirm("Ar tikrai norite Nepatvirtinti?")
		if (answer){
			commentUnconfirm2(nr,docnr,'');				
		}
	}	
}

//-->
</SCRIPT>

<?php
if (isset($oldstyle) && $oldstyle == "1") {

	$f = '<br><br>';
	$f .= '<div style="border-left:1px solid #000000;">Sąskaitos požymis<br><br>';
	$f .= '<input class="but" type=button onClick="parent.location=\'' . $script . '?poz=new\'" value=\'Nauja\'><br>';
	$f .= '<input class="but" type=button onClick="parent.location=\'' . $script . '?poz=conf\'" value=\'Patvirtinta\'><br>';
	$f .= '<input class="but" type=button onClick="parent.location=\'' . $script . '?poz=unconf\'" value=\'Nepatvirtinta\'><br>';
	$f .= '<input class="but" type=button onClick="parent.location=\'' . $script . '?poz=all\'" value=\'Visos\'>';
	if (isset($adm_menu) && $kreditas == "1") {
		$f .= '<br><input class="but" type=button onClick="parent.location=\'' . $script . '?poz=neperk\'" value=\'Tik neperkeltos\'>';
	}
	$f .= '</div>';
	if (isset($adm_menu)) {
		$f .= '<br>';
		$f .= '<div style="border-left:1px solid #000000;">Periodas<br><br>';
		$f .= '<form method="post" action="' . $script . '?poz=' . $poz . '">';
		$f .= '<table cellspacing="0" cellpadding="1" border = "0">';
		$f .= '<tr><td align="right">Periodas nuo</td><td><input class="dt" type=\'text\' name="from" value="' . $_SESSION['from'] . '"></td></tr>';
		$f .= '<tr><td align="right">iki</td><td><input  class="dt" type=\'text\' name="to" value="' . $_SESSION['to'] . '"></td></tr>';
		$f .= '<tr><td align="right" colspan="2"><input type = "submit" value = "Keisti"></td></tr>';
		$f .= '</table>';
		$f .= '</form>';
		$f .= '<br>';
		if ($poz=="neperk") {
			$f .= '<SCRIPT language="JavaScript">'."\n";
			$f .= '<!--'."\n";
			$f .= 'function spausdinti(){'."\n";
			$f .= '	parent.location=\'printall.php?poz=' . $poz . '&from=' . $_SESSION['from'] . '&to=' . $_SESSION['to'] . '\';'."\n";
			$f .= '}'."\n";
			$f .= '-->'."\n";
			$f .= '</script>'."\n";
			$f .= '<input id="spsd" class="but" type=button onClick="spausdinti();" value=\'Spausdinti\'>';
		} 
		$f .= '</div>';
	}
	
	$f .= '<br>';
	$f .= '<div style="width:180px;text-align:left;padding-left:15px;" >';
	$f .= '<img src=\'img/green.gif\' alt=\'\' title=\'\'> - Nauja<br>';
	$f .= '<img src=\'img/red.gif\' alt=\'\' title=\'\'> - Patvirtinta<br>';
	$f .= '<img src=\'img/blue.gif\' alt=\'\' title=\'\'> - Nepatvirtinta<br>';
	$f .= '</div>';

	$d = "";
	if ($poz == "all") {
		$d .= "Visos sąskaitos";
	} else if ($poz == "conf") {
		$d .= "Patvirtintos sąskaitos";
	} else if ($poz == "unconf") {
		$d .= "Nepatvirtintos sąskaitos";
	} else if ($poz == "neperk") {
		$d .= "Neperkeltos sąskaitos";
	} else {
		$d .= "Naujos sąskaitos";
	}
	
} else {
?>
<script type="text/javascript">
	$(document).ready(function(){	

		if (!$.browser.opera) {
    
			// select element styling
			$('select.select').each(function(){
				var title = $(this).attr('title');
				if( $('option:selected', this).val() != ''  ) title = $('option:selected',this).text();
				$(this)
					.css({'z-index':10,'opacity':0,'-khtml-appearance':'none'})
					.after('<span class="select">' + title + '</span>')
					.change(function(){
						val = $('option:selected',this).text();
						$(this).next().text(val);
						})
			});

		};
		
	});
</script>
<script>
  $(function() {
    $( ".dt" ).datepicker({
      showOn: "button",
      buttonImage: "img/calendar.gif",
      buttonImageOnly: true,
	  dateFormat: "yy.mm.dd",
	  regional: "lt"
    });
  });
  </script>
<?php	
	$f = "<br><form method=\"post\" action='" . $script . "'><table cellspacing='0' cellpadding='5' class='params'>";
		$f .= "<tr><th>Sąskaitos požymis:</th></tr>";
	$f .= "<tr><td style='text-align:left;'>";
        $f .= '<div>';
        $f .= '<select name="poz" class="select" >';
		$f .= "<option value=\"new\"";  if ($poz=="new") {$f .= 'selected="selected"';}$f .= ">Nauja</option>";
		$f .= "<option value=\"conf\"";  if ($poz=="conf") {$f .= 'selected="selected"';}$f .= ">Patvirtinta</option>";
		$f .= "<option value=\"unconf\"";  if ($poz=="unconf") {$f .= 'selected="selected"';}$f .= ">Nepatvirtinta</option>";
		$f .= "<option value=\"all\"";  if ($poz=="all") {$f .= 'selected="selected"';}$f .= ">Visos</option>";
		if (isset($adm_menu) && $kreditas == "1") {
			$f .= "<option value=\"neperk\"";  if ($poz=="neperk") {$f .= 'selected="selected"';}$f .= ">Tik neperkeltos</option>";
		}
		$f .= '</select>';
        $f .= '</div>		';
	$f .= "</td></tr>";
	if (isset($adm_menu)) {
		$f .= "<tr><th>Pasirinkite periodą:</th></tr>";
		$f .= "<tr><td>Nuo&nbsp;&nbsp;&nbsp;<input class=\"dt\" type='text' name=\"from\" value=\"" . $_SESSION['from'] ."\"></td></tr>";
		$f .= "<tr><td>Iki&nbsp;&nbsp;&nbsp;<input class=\"dt\" type='text' name=\"to\" value=\"" . $_SESSION['to'] ."\"></td></tr>";
	}
	$f .= "<tr><td ><input class='but bgfilter' type = \"submit\" value = \"Rodyti\"></td></tr>";
	if ($poz=="neperk") {
		$f .= "<tr><td >";
		$f .= '<SCRIPT language="JavaScript">'."\n";
		$f .= '<!--'."\n";
		$f .= 'function spausdinti(){'."\n";
		$f .= '	parent.location=\'printall.php?poz=neperk&from=' . $_SESSION['from'] . '&to=' . $_SESSION['to'] . '\';'."\n";
		$f .= '}'."\n";
		$f .= '-->'."\n";
		$f .= '</script>'."\n";
		$f .= '<input id="spsd" class="but bgfilter" type=button onClick="spausdinti();" value=\'Spausdinti\'>';
		$f .= "</td></tr>";
	} 	
	$f .= "</table></form>";

	$d="";
	
}





if (!empty($accounts) || !empty($accounts2)) {

	$d .= '<br>';
	$d .= '<table cellspacing="0" cellpadding="2" class="innercont2">';
	if (!isset($oldstyle) || $oldstyle != "1") {
		$d .= '<tr><th>Data</th><th nowrap>Dokumento nr.</th><th>Gavėjas</th><th>Suma</th><th colspan="2">Patvirtinimas</th><th align="center" colspan="2">PDF</th></tr>';
		$imgnew = "_new";
	} else {
		$d .= '<tr style="background-color:#B9B2A5;"><td>Data</td><td>Dokumento nr.</td><td>Gavėjas</td><td>Suma</td><td colspan="2">Patvirtinimas</td><td align="center" colspan="2">PDF</td></tr>';
		$imgnew = "_new";
	}

	$nepsuma = 0;

	if (isset($accounts)) {
	foreach ($accounts as $account) {
		$d .="<tr><td>".$account["I31_OP_DATA"]."</td>";
		$d .="<td>".@iconv('windows-1257', 'UTF-8',$account["I32_DOK_NR"])."</td>";
		$d .="<td>".@iconv('windows-1257', 'UTF-8',$account["I31_PASTABOS"]);
		$com = getDocComment($db_rdata,$account["I32_DOK_NR"]);
		if ($com != null && trim($com) != ""){
			$d .= "<br><span class='comment'>Komentaras: ". $com . "</span>";
		}
		$d .="</td>";
		if (!isset($DEB_KRED_TIPAS) || $DEB_KRED_TIPAS != "1") {
			$d .="<td>".$account["I32_DEB_SUMA"]."</td>";
			$nepsuma += $account["I32_DEB_SUMA"];
		} else {
			$nq = str_replace("<dok_nr>", addslashes_mssql($account["I32_DOK_NR"]), $nestnuol_q);
			$nuol = $db_www->returnInfo($nq);			
			$nuolaida = $nuol['nuolaida'];
				
			$npq = str_replace("<dok_nr>", addslashes_mssql($account["I32_DOK_NR"]), $nestnuolpvm_q);
			$nuolpvm = $db_www->returnInfo($npq);	
			$nuolaidos_pvm = $nuolpvm['nuolpvm'];
			$s = ($account["I32_DEB_SUMA"]-$nuolaida-$nuolaidos_pvm);
			$d .="<td>".$s."</td>";
			$nepsuma += $s;
		}
		if (!isset($adm_menu)) {
			if (trim($account["I31_KODAS_LS_4"]) == "+") {
				$d .="<td style='text-align:center;'><A onclick=\"stat('-','".@iconv('windows-1257', 'UTF-8', trim($account["i31_kodas_kr"]))."','".@iconv('windows-1257', 'UTF-8',$account["I32_DOK_NR"])."');\"><img src='img/red_new.gif' alt='Nepatvirtinti' title='Netvirtinti'></A></td><td><A class='card2' href='#' OnClick=\"stat('-','".@iconv('windows-1257', 'UTF-8', trim($account["i31_kodas_kr"]))."','".@iconv('windows-1257', 'UTF-8',$account["I32_DOK_NR"])."')\">Netvirtinti</A></td>";
			} else if (trim($account["I31_KODAS_LS_4"]) == "-") {
				$d .="<td style='text-align:center;'><A onclick=\"stat('+','".@iconv('windows-1257', 'UTF-8', trim($account["i31_kodas_kr"]))."','".@iconv('windows-1257', 'UTF-8',$account["I32_DOK_NR"])."');\"><img src='img/blue_new.gif' alt='Patvirtinti' title='Patvirtinti'></A></td><td><A class='card2' href='#' OnClick=\"stat('+','".@iconv('windows-1257', 'UTF-8', trim($account["i31_kodas_kr"]))."','".@iconv('windows-1257', 'UTF-8',$account["I32_DOK_NR"])."')\">Patvirtinti</A></td>";
			} else {
				$d .="<td style='text-align:center;'><A onclick=\"stat('+','".@iconv('windows-1257', 'UTF-8', trim($account["i31_kodas_kr"]))."','".@iconv('windows-1257', 'UTF-8',$account["I32_DOK_NR"])."');\"><img src='img/green_new.gif' alt='Patvirtinti' title='Patvirtinti'></A></td><td><A class='card2' href='#' OnClick=\"stat('+','".@iconv('windows-1257', 'UTF-8', trim($account["i31_kodas_kr"]))."','".@iconv('windows-1257', 'UTF-8',$account["I32_DOK_NR"])."')\">Patvirtinti</A></td>";
			}
		} else {
			if ($poz != "neperk") {
				if (trim($account["I31_KODAS_LS_4"]) == "+") {
					$d .="<td style='text-align:center;' colspan='2'><img src='img/red".$imgnew.".gif' alt='Nepatvirtinti' title='Netvirtinti'></td>";
				} else if (trim($account["I31_KODAS_LS_4"]) == "-") {
					$d .="<td style='text-align:center;' colspan='2'><img src='img/blue".$imgnew.".gif' alt='Patvirtinti' title='Patvirtinti'></td>";
				} else {
					$d .="<td style='text-align:center;' colspan='2'><img src='img/green".$imgnew.".gif' alt='Patvirtinti' title='Patvirtinti'></td>";
				}	
			}	else {
					$d .="<td></td><td></td>";		
			}
		}
		
		if (!isset($adm_menu)) {			
			$d .= '<td><A class="card" href="#" onClick="parent.location=\'printaccounts.php?dok_nr='. @iconv('windows-1257', 'UTF-8',trim($account["I32_DOK_NR"])) . '\'">Peržiūrėti</A>';
		} else {
			$qr = str_replace("<kodas>", trim($account['I32_KODAS_KS']), $ii_query);
			$qri = $db_www->returnInfo($qr);
			$d .="<td style='vertical-align:middle;' nowrap>".$account["I31_KODAS_LS_4"]. " ";
			$d .="<A class=\"card\" href='#' onClick=\"parent.location='printaccounts.php?im_kodas=".trim($account['I32_KODAS_KS'])."&dok_nr=" . iconv('windows-1257', 'UTF-8',trim($account["I32_DOK_NR"]))."&nopdf=0'\">Peržiūrėti</A>";
			if (isset($qri["n60_kodas_sm"])) {
				$uid = trim($qri["n60_kodas_sm"]);
				$pass= $qri["n60_pareigos"];
				$d .= '&nbsp;&nbsp;<A class="card2" href="nauja.php?id=' . $uid . '&p=' . md5(trim($pass)) . '" target="_blank">Kliento sistema</A>';
			}			
		}
		$d .="</td><td><A href='#' onclick=\"comment('".$account["I32_DOK_NR"]."','".str_replace("'","\'",$com)."');\"><img border='0' src='img/comment.png' alt='Komentaras' title='Komentaras'></A></td>";
		
		$d.='</tr>';
		
	}
	}
	foreach ($accounts2 as $account) {
		if ($account["I06_OP_TIP"] == "52") {
			$cred= "1";
		} else {
			$cred= "0";
		}
		$d .="<tr><td>".$account["I06_OP_DATA"]."</td>";
		$d .="<td>".@iconv('windows-1257', 'UTF-8',$account["I06_DOK_NR"])."</td>";
		$d .="<td>".@iconv('windows-1257', 'UTF-8',$account["i06_pav"]);
		
		$com = getDocComment($db_rdata,$account["I06_DOK_NR"]);
		if ($com != null && trim($com) != ""){
			$d .= "<br><span class='comment'>Komentaras: ". $com . "</span>";
		}
		$d .="</td>";
		
		
		$d .="<td>".$account["i06_suma"]."</td>";
		$nepsuma += $account["i06_suma"];
		if (!isset($adm_menu)) {
			if (trim($account["i06_kodas_ls_4"]) == "+") {
				$d .="<td style='text-align:center;'><A onclick=\"status2('-','".@iconv('windows-1257', 'UTF-8', trim($account["I06_KODAS_PO"]))."','".@iconv('windows-1257', 'UTF-8',$account["I06_DOK_NR"])."');\"><img src='img/red".$imgnew.".gif' alt='Netvirtinti' title='Netvirtinti'></A></td><td><A href='#' class='card2' onClick=\"status2('-','".@iconv('windows-1257', 'UTF-8', trim($account["I06_KODAS_PO"]))."','".@iconv('windows-1257', 'UTF-8',$account["I06_DOK_NR"])."')\">Netvirtinti</A></td>";
			} else if (trim($account["i06_kodas_ls_4"]) == "-") {
				$d .="<td style='text-align:center;'><A onclick=\"status2('+','".@iconv('windows-1257', 'UTF-8', trim($account["I06_KODAS_PO"]))."','".@iconv('windows-1257', 'UTF-8',$account["I06_DOK_NR"])."');\"><img src='img/blue".$imgnew.".gif' alt='Patvirtinti' title='Patvirtinti'></A></td><td><A href='#' class='card2' onClick=\"status2('+','".@iconv('windows-1257', 'UTF-8', trim($account["I06_KODAS_PO"]))."','".@iconv('windows-1257', 'UTF-8',$account["I06_DOK_NR"])."')\">Patvirtinti</A></td>";
			} else {
				$d .="<td style='text-align:center;'><A onclick=\"status2('+','".@iconv('windows-1257', 'UTF-8', trim($account["I06_KODAS_PO"]))."','".@iconv('windows-1257', 'UTF-8',$account["I06_DOK_NR"])."');\"><img src='img/green".$imgnew.".gif' alt='Patvirtinti' title='Patvirtinti'></A></td><td><A href='#' class='card2' onClick=\"status2('+','".@iconv('windows-1257', 'UTF-8', trim($account["I06_KODAS_PO"]))."','".@iconv('windows-1257', 'UTF-8',$account["I06_DOK_NR"])."')\">Patvirtinti</A></td>";
			}
		} else {
			
				if (trim($account["i06_kodas_ls_4"]) == "+") {
					$d .="<td style='text-align:center;' colspan='2'><img src='img/red".$imgnew.".gif' alt='Netvirtinti' title='Netvirtinti'></td>";
				} else if (trim($account["i06_kodas_ls_4"]) == "-") {
					$d .="<td style='text-align:center;' colspan='2'><img src='img/blue".$imgnew.".gif' alt='Patvirtinti' title='Patvirtinti'></td>";
				} else {
					$d .="<td style='text-align:center;' colspan='2'><img src='img/green".$imgnew.".gif' alt='Patvirtinti' title='Patvirtinti'></td>";
				}	
			
		}
		if (!isset($adm_menu)) {			
			$d .= '<td><A class="card" href="#" onClick="parent.location=\'printaccounts.php?cred=' . $cred . '&type=p&dok_nr=' . @iconv('windows-1257', 'UTF-8',trim($account["I06_DOK_NR"])) . '&id=' . @iconv('windows-1257', 'UTF-8',trim($account["I06_KODAS_PO"])) . '\'">Peržiūrėti</A>';
		} else {
			
			$qr = str_replace("<kodas>", trim($account['i06_kodas_ks']), $ii_query);
			
			$qri = $db_www->returnInfo($qr);
			$d .="<td>".$account["i06_kodas_ls_4"]. " ";
			$d .="<A href='#' class=\"card\" onClick=\"parent.location='printaccounts.php?cred=". $cred ."&im_kodas=".trim($account['i06_kodas_ks'])."&type=p&dok_nr=".@iconv('windows-1257', 'UTF-8',trim($account["I06_DOK_NR"]))."&id=". @iconv('windows-1257', 'UTF-8',trim($account["I06_KODAS_PO"]))."&nopdf=0'\">Peržiūrėti</A>";
			if (isset($qri["n60_kodas_sm"])) {
				$uid = trim($qri["n60_kodas_sm"]);
				$pass= $qri["n60_pareigos"];			
				$d .= '&nbsp;&nbsp;<A class="card2" href="nauja.php?id=' . $uid . '&p=' . md5(trim($pass)) . '" target="_blank">Kliento sistema</A>';
			}
					
		}		
		$d .="</td><td><A href='#' onclick=\"comment('".$account["I06_DOK_NR"]."','".str_replace("'","\'",$com)."');\"><img border='0' src='img/comment.png' alt='Komentaras' title='Komentaras'></A></td>";
		$d .= '</tr>';
	}
	if ($poz == "neperk") {	
		$d .= '<tr><td colspan="3" align="right">Iš viso:</td><td>' . $nepsuma .'</td><td colspan="3"></td></tr>';
	}	
	if (!isset($oldstyle) || $oldstyle != "1") {
	$d .= "<tr><td colspan='7' style='text-align:right;'><img src='img/green_new.gif' alt='' title=''> - Nauja <img src='img/red_new.gif' alt='' title=''> - Patvirtinta <img src='img/blue_new.gif' alt='' title=''> - Nepatvirtinta</td></tr>";
	}
	$d .= '</table>';
}
?>










<table class="innercont" cellspacing="0" cellpadding="5">
<tr><td class="leftcol">
<?php
if (isset($oldstyle) && $oldstyle == "1") {
	echo $d;
} else {
	echo $f;
}
?>
</td><td rowspan="2" class="rightcol">
<?php
if (isset($oldstyle) && $oldstyle == "1") {
	echo $f;
} else {
	echo $d;
}
?>
</td></tr>
<tr><td >

</td></tr>
</table>
<?php
include("footer.php");
?>